package com.tinyspot.concrete.common.convert;

import com.tinyspot.concrete.common.entity.Order;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

@Mapper
public interface MapStructMapper {
    MapStructMapper INSTANCE = Mappers.getMapper(MapStructMapper.class);

    @Mapping(source = "name", target = "orderName")
    // @Mapping(source = "flag", target = "flagDesc", qualifiedByName = "booleanToString")
    OrderDTO convert(Order order);


    // @Named("booleanToString")
    // default String booleanToString(boolean flag) {
    //     return flag ? "是" : "否";
    // }

    public static void main(String[] args) {
        MapStructMapper mapper = MapStructMapper.INSTANCE;
        Order order = new Order(1001L, "A001", "Apple", true);
        OrderDTO convert = mapper.convert(order);
        System.out.println(convert);
    }
}
